package web;

import java.io.IOException; 
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import metier.Filiere;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import dao.DaoImpl;


@SuppressWarnings("serial")
public class ControleurServlet extends HttpServlet {

	private String name;
	JSONObject json      = new JSONObject();
	
	public void init() throws ServletException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		/* response.setContentType("application/json");
		 PrintWriter out=response.getWriter();
		 name=request.getParameter("name");
		 out.print("{\"name\":\""+name+"\"}");
		 try {
			json.put("res","{id:89,name:"+name+"}");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 response.setContentType("application/json");
		 response.getWriter().write(json.toString());
		 */
		 
			 DaoImpl dao=new DaoImpl();
			 String nom=request.getParameter("nom_filiere");
			 int num=(int) Double.parseDouble(request.getParameter("id_filiere"));
			 dao.addFiliere(new Filiere(num,nom));
		 
		 
	}

	
}
